<!DOCTYPE html>
<html lang="en" class="page-fill">
<head>
    <meta charset="UTF-8">
    <title>Vpay - 后台登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/i/img/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="/i/css/oksub.css"/>
</head>
<body class="page-fill">
    <div class="page-fill" id="login">
        <form class="layui-form">
            <div class="login_face"><img src="/i/img/logo.png"></div>
            <div class="layui-form-item input-item">
                <label for="username">用户名</label>
                <input type="text" lay-verify="required" name="username" placeholder="请输入账号" autocomplete="off" id="username" class="layui-input">
            </div>
            <div class="layui-form-item input-item">
                <label for="password">密码</label>
                <input type="password" lay-verify="required|password" name="password" placeholder="请输入密码" autocomplete="off" id="password" class="layui-input">
            </div>
            <div class="layui-form-item input-item captcha-box">
                <label for="captcha">验证码</label>
                <input type="text" lay-verify="required|captcha" name="captcha" placeholder="请输入验证码" autocomplete="off" id="captcha" maxlength="4" class="layui-input">
                <div class="img ok-none-select" id="captchaImg">
                    <img style="height: 36px;width: 100px;" src="<{url m='admin' c='main' a='Captcha'}>"  onclick="this.src=this.src+'?c='+Math.random();" >
                </div>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-block" lay-filter="login" lay-submit="">登录</button>
            </div>
        </form>
    </div>
    <!--js逻辑-->
    <script src="/i/js/aes.js"></script>
    <script src="/i/lib/layui/layui.js"></script>
    <script>
        layui.use(["form", "okUtils", "okLayer"], function () {
            let form = layui.form;
            let $ = layui.jquery;

            let okUtils = layui.okUtils;
            let okLayer = layui.okLayer;
            /**
             * 表单提交
             */
            form.on("submit(login)", function (data) {

                okUtils.ajax("<{url m='admin' c='main' a='key'}>","post",null,true).done(function (d) {
                    const key = d.key;
                    data.field.password=Encrypt(data.field.password,key);
                    okUtils.ajax("<{url m='admin' c='main' a='receive'}>", "post", data.field, true).done(function (response) {
                        okLayer.greenTickMsg(response.msg, function () {
                            window.location.reload();
                        })
                    }).fail(function (error) {
                        console.log(error)
                    });
                });
                return false;
            });

            /**
             * 表单input组件单击时
             */
            $("#login .input-item .layui-input").click(function (e) {
                e.stopPropagation();
                $(this).addClass("layui-input-focus").find(".layui-input").focus();
            });

            /**
             * 表单input组件获取焦点时
             */
            $("#login .layui-form-item .layui-input").focus(function () {
                $(this).parent().addClass("layui-input-focus");
            });

            /**
             * 表单input组件失去焦点时
             */
            $("#login .layui-form-item .layui-input").blur(function () {
                $(this).parent().removeClass("layui-input-focus");
                if ($(this).val() != "") {
                    $(this).parent().addClass("layui-input-active");
                } else {
                    $(this).parent().removeClass("layui-input-active");
                }
            })
        });
    </script>
</body>
</html>
